<template>
  <li>
    <input type="checkbox" @change="select($event)" :checked="item.finished" />
    <span>{{ item.content }}</span>
    <a href="javascript:;" @click.prevent="deleteItem"></a>
  </li>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  props: {
    item: {
      type: Object,
      default: null
    }
  },
  methods: {
    ...mapActions(['change_todo', 'delete_item']),
    select(e) {
      if (e.target.checked) {
        // 未完成->完成
        this.$store.dispatch('change_todo', { id: this.item.id, flag: e.target.checked })
      } else {
        // 完成回档到->未完成
        this.$store.dispatch('change_todo', { id: this.item.id, flag: e.target.checked })
      }
    },
    deleteItem() {
      this.$store.dispatch('delete_item', this.item)
    }
  }
}
</script>

<style lang="less" scoped>
li {
  position: relative;
  margin-bottom: 15px;
  height: 32px;
  line-height: 32px;
  border-radius: 5px;
  border-left: 5px solid #629a9c;
  padding-left: 10px;
  background-color: #fff;
  input {
    height: 26px;
    width: 26px;
    border: 1px solid black;
    cursor: pointer;
  }
  span {
    display: inline-block;
    margin-left: 10px;
    height: 100%;
    font-size: 16px;
    vertical-align: top;
  }
  a {
    position: absolute;
    top: 2px;
    right: 3px;
    display: inline-block;
    width: 14px;
    height: 12px;
    border-radius: 14px;
    border: 6px double #fff;
    background-color: #fd5c2e;
  }
}
</style>
